#include "PlayerContainer.h"
#include "ConnectionProcessor.h"

PlayerContainer::PlayerContainer(int capacity) : NodeStorage(capacity) {

}



void PlayerContainer::handle_connection(Socket* socket) {
	cout << "Connection from " << socket->ip << "\n";
	Player* p = process_connection(socket, this);
	if(p != 0)
	{
		add(p, p->entity_index);
		cout << p->username << " has logged in with entity index " << p->entity_index << " and NGI-index " << p->ngi_index << ".\n";
	}
}

int PlayerContainer::get_ngi_index(char* name) {
	for(int i = 0; i < nodes.count; i++)
	{
		if(strcmp(((Player*)nodes.nodes[i])->username, name) == 0)
			return i;
	}

	return -1;
}

PlayerContainer::~PlayerContainer(void) {
}